package com.xidian.zhiancloud.service.luling.RiskWarSignManageStatusPart;

import com.xidian.zhiancloud.dao.RiskWarSignManageStatusMapper;
import com.xidian.zhiancloud.enums.GeneralResponseEnums;
import com.xidian.zhiancloud.exception.CustomizeException;
import com.xidian.zhiancloud.model.RiskWarSignManageStatus;
import com.xidian.zhiancloud.model.RiskWarSignManageStatusExample;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service

public class RiskWarSignManageStatusService {
    @Autowired
    private RiskWarSignManageStatusMapper  riskWarSignManageStatusMapper;
    //添加
    public void insert(RiskWarSignManageStatus riskWarSignManageStatus) {
        int count = riskWarSignManageStatusMapper.insert(riskWarSignManageStatus);
        if (count == 0) {
            throw new CustomizeException(GeneralResponseEnums.SYSTEM_ERROR);
        }
    }
        //删除
        public void delete(RiskWarSignManageStatus  riskWarSignManageStatus){
            RiskWarSignManageStatusExample example = new RiskWarSignManageStatusExample();
            RiskWarSignManageStatusExample.Criteria criteria = example.createCriteria();
            criteria.andIdEqualTo(riskWarSignManageStatus.getId());
            int count = riskWarSignManageStatusMapper.deleteByExample(example);
            if (count == 0) {
                throw new CustomizeException(GeneralResponseEnums.SYSTEM_ERROR);
            }
        }
        //更新
    public void update(RiskWarSignManageStatus riskWarSignManageStatus) {
        RiskWarSignManageStatusExample example = new RiskWarSignManageStatusExample();
        RiskWarSignManageStatusExample.Criteria criteria = example.createCriteria();
        criteria.andIdEqualTo(riskWarSignManageStatus.getId());
        RiskWarSignManageStatus personAdd = new RiskWarSignManageStatus();
        personAdd.setPersonAdd(riskWarSignManageStatus.getPersonAdd());
        int count = riskWarSignManageStatusMapper.updateByExampleSelective(personAdd, example);
        if (count == 0) {
            throw new CustomizeException(GeneralResponseEnums.SYSTEM_ERROR);
        }
    }
    //批量删除
    public void deleteByIds(Long[] ids) {
        for (Long id : ids) {
            int result = riskWarSignManageStatusMapper.deleteByPrimaryKey(id);
            if (result == 0) {
                throw new CustomizeException(GeneralResponseEnums.SYSTEM_ERROR);
            }
        }
    }
    //通过是否完好查询
    public List<RiskWarSignManageStatus> getById(String isCondition) {
        RiskWarSignManageStatusExample riskWarSignManageStatusExample = new RiskWarSignManageStatusExample();
        RiskWarSignManageStatusExample.Criteria criteria = riskWarSignManageStatusExample.createCriteria();
        criteria.andIsConditionEqualTo(isCondition);
        List<RiskWarSignManageStatus> riskWarSignManageStatusList = riskWarSignManageStatusMapper.selectByExample(riskWarSignManageStatusExample);
        if (riskWarSignManageStatusList == null) {
            throw new CustomizeException(GeneralResponseEnums.SYSTEM_ERROR);
        }
        return riskWarSignManageStatusList;
    }
    //关键字搜索
    public Object getList(String typeWarning, String nameWarning, String locale,String key, int current, int size) {
        RiskWarSignManageStatusExample riskWarSignManageStatusExample = new RiskWarSignManageStatusExample();
        RiskWarSignManageStatusExample.Criteria criteria1 = riskWarSignManageStatusExample.createCriteria();
        RiskWarSignManageStatusExample.Criteria criteria2 = riskWarSignManageStatusExample.createCriteria();
        RiskWarSignManageStatusExample.Criteria criteria3 = riskWarSignManageStatusExample.createCriteria();
        criteria1.andUnitEqualTo(typeWarning);
        criteria2.andUnitEqualTo(typeWarning);
        criteria3.andUnitEqualTo(typeWarning);
        if (nameWarning != null) {
            criteria1.andPersonAddEqualTo(nameWarning);
            criteria2.andPersonAddEqualTo(nameWarning);
            criteria3.andPersonAddEqualTo(nameWarning);
        }
        if (locale != null) {
            criteria1.andNameWarningEqualTo(locale);
            criteria2.andNameWarningEqualTo(locale);
            criteria3.andNameWarningEqualTo(locale);
        }
        if (key!= null && !"".equals(key)) {
            criteria1.andNameWarningEqualTo('%' + key + '%');
            criteria2.andPersonAddEqualTo('%' + key + '%');
            criteria3.andUnitEqualTo('%' + key + '%');
            riskWarSignManageStatusExample.or(criteria2);
            riskWarSignManageStatusExample.or(criteria3);
        }
        return riskWarSignManageStatusMapper.selectByExampleWithRowbounds(riskWarSignManageStatusExample, new RowBounds(current, size));
    }
}
